package com.company.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;


@RestController
public class PostRequestController {
    @PostMapping("/submit")
    public String getPost(HttpServletRequest request) throws Exception {
        StringBuilder requestBody = new StringBuilder();
        // 处理 POST 请求时，如果前端以原始数据（例如 JSON 数据）提交时，可以通过 getReader() 读取整个请求体。
        BufferedReader reader = request.getReader();
        String line;
        while((line = reader.readLine())!= null){
            requestBody.append(line);
        }
        String jsonData = requestBody.toString();
        System.out.println("接收到的数据为：" + jsonData);
        return "ok";
    }
}
